<template>
	<div>
		<!-- 头部 -->
		<nav-bar />
		<!-- 用户中心头部 -->
		<user-header :userinfo="userInfo" />
		<!-- 用户动态以及视频-->
		<user-article />
	</div>
</template>

<script>
	import { getUserInfo } from '@/api'
	import NavBar from '@/components/common/NavBar.vue'
	import UserHeader from './user-header.vue'
	import UserArticle from './user-article.vue'
	export default {
		name: 'userinfo',
		created() {
			this._getUserInfo()
		},
		data() {
			return {
				// 用户信息对象
				userInfo: {}
			}
		},
		methods: {
			// 获取用户信息
			_getUserInfo() {
				// 获取token
				const tokenStr = window.localStorage.getItem('token')
				// 判断是否有token
				if (!tokenStr) return this.$router.push({name: 'Login'})
				const id = window.localStorage.getItem('id')
				// 发送请求
				getUserInfo(id)
				.then(({data: res}) => {
					console.log('获取用户信息',res[0])
					this.userInfo = res[0]
				})
				.catch(err => {
					this.$toast.fail('请求失败,请重新尝试!')
				})
			}
		},
		components: {
			NavBar,
			UserHeader,
			UserArticle
		}
	}
</script>

<style scoped>

</style>